#pragma once
#include <string>
#include <vector>
#include <optional>
#include <shared_mutex>
#include <nlohmann/json.hpp>

namespace gateway::beast_http {

struct Route {
    std::string prefix;       // "/api/ping"
    std::string service_name; // "ping_service"
};

class Router {
public:
    void add(const std::string& prefix, const std::string& service);
    bool load_from_json(const nlohmann::json& routes_array); // routes: [{prefix,service}]
    std::optional<std::string> match(const std::string& path) const; // 返回 service_name
private:
    std::vector<Route> routes_;
    mutable std::shared_mutex mutex_;
};

} // namespace gateway::beast_http
